/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function iniciarPaginaEditar(){
    var x;
    x=$(document);
    x.ready(inicializarEventosEditar);
}


function inicializarEventosEditar(){
    var botonera_scroller_anchor = $(".barS.scroller_anchor").offset().top;
    var barHeight=$(".bar").css('height');
    barHeight=quitarPx(barHeight);
    var barMargin=$('.bar').css('margin-bottom');
    barMargin=quitarPx(barMargin);
    var botoneraHeight=$('.botoneraEditar.scroller').css('height');
    botoneraHeight=quitarPx(botoneraHeight);
    var totalHeight=barMargin+barHeight+"px";
    var volverASuSitio=quitarPx($(".header").css('height'));
    $(window).scroll(function(){
       fixBotoneraYBarraEditar(botonera_scroller_anchor,barHeight,barMargin,botoneraHeight,totalHeight,volverASuSitio);
    });
}




function fixBotoneraYBarraEditar(botonera_scroller_anchor,barHeight,barMargin,botoneraHeight,totalHeight,volverASuSitio){   
    if($(this).scrollTop() >= botonera_scroller_anchor && $('.botoneraEditar.scroller').css('position') != 'fixed' && $('.bar').css('position') != 'fixed'){
            $('.botoneraEditar.scroller').css({
                'position': 'fixed',
                'top': totalHeight,
                'z-index':'4'
            });
            $('.botoneraEditar.scroller_anchor').css('height', barHeight+barMargin+botoneraHeight+"px");
            $('.bar').css({
                'position': 'fixed',
                'top': '0px',
                'z-index':'4'
            });
        }
        else if($(this).scrollTop() < volverASuSitio && $('.botoneraEditar.scroller').css('position') != 'relative' && $('.bar').css('position') != 'relative'){
            $('.botoneraEditar.scroller_anchor').css('height', '0px');
            $('.botoneraEditar.scroller').css({
                'position': 'relative',
                'top':'0px'
            });
             $('.candidateBar.scroller_anchor').css('height', '0px');
            $('.bar').css({
                'position': 'relative',
                'top':'0px'
            });
        }
}

function fixBotoneraEditar(e){
    var botonera_scroller_anchor = $(".botoneraEditar.scroller_anchor").offset().top;
    if($(this).scrollTop() >= botonera_scroller_anchor && $('.botoneraEditar.scroller').css('position') != 'fixed'){
            $('.botoneraEditar.scroller').css({
                'position': 'fixed',
                'top': '0px',
                'z-index':'4'
            });
            $('.botoneraEditar.scroller_anchor').css('height', $(".botoneraEditar.scroller").css('height'));
        }
        else if($(this).scrollTop() < botonera_scroller_anchor && $('.botoneraEditar.scroller').css('position') != 'relative'){
            $('.botoneraEditar.scroller_anchor').css('height', '0px');
            $('.botoneraEditar.scroller').css({
                'position': 'relative'
            });
        }
}

function quitarPx(string){
    return (string.substring(0,string.length - 2))*1;
}